# coding=utf-8
from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User
# from django.utils import timezone
import django.utils.timezone as timezone

# Create your models here.

BOOL_CHOICES = (('男', '男'), ('女', '女'))


class register(models.Model):  # 前台注册用户
    username = models.CharField(max_length=20)  # 用户名
    password = models.CharField(max_length=30)  # 密码
    repassword = models.CharField(max_length=30)  # 确认密码
    sex = models.CharField(max_length=4, choices=BOOL_CHOICES)  # 性别
    phone = models.BigIntegerField(blank=False)  # 电话

    def _unicode_(self):
        return self.username


class TimeStampedModel(models.Model):
    creatdate = models.DateField(default=timezone.now())

    class Meta:
        abstract = True


class download(TimeStampedModel):  # 下载页面
    title = models.CharField(blank=False, max_length=100)  # 主题
    link = models.CharField(blank=True, max_length=100)  # 链接
    # creatdate = models.CharField(blank=True, max_length=100)
    password = models.CharField(blank=True, max_length=10)  # 密码
    uploader = models.ForeignKey(User, blank=False, null=True)

    def _unicode_(self):
        return self.uploader.username

    class Meta:
        ordering = ['-id']


class Category(models.Model):
    name = models.CharField(max_length=40, verbose_name=u'名称')
    # parent = models.ForeignKey('self', default=None, blank=True, null=True,
    #                            verbose_name=u'上级分类')
    rank = models.IntegerField(default=0, verbose_name=u'排序')
    create_time = models.DateTimeField(u'创建时间', default=timezone.now)

    class Meta:
        verbose_name_plural = verbose_name = u'分类'
        ordering = ['rank', '-create_time']

    def __unicode__(self):
        return self.name


class Article(models.Model):
    author = models.ForeignKey(User, verbose_name=u'作者', blank=False, null=True)
    category = models.ForeignKey(Category, verbose_name=u'分类', null=True)
    title = models.CharField(max_length=100, verbose_name=u'标题')
    en_title = models.CharField(max_length=100, verbose_name=u'英文标题')
    img = models.CharField(max_length=200,
                           default='/static/img/article/default.jpg')
    tags = models.CharField(max_length=200, null=True, blank=True,
                            verbose_name=u'标签', help_text=u'用逗号分隔')
    summary = models.TextField(verbose_name=u'摘要')
    content = models.TextField(verbose_name=u'正文')
    view_times = models.IntegerField(default=0)
    zan_times = models.IntegerField(default=0)

    is_top = models.BooleanField(default=False, verbose_name=u'置顶')
    rank = models.IntegerField(default=0, verbose_name=u'排序')

    # pub_time = models.DateTimeField(default=False, verbose_name=u'发布时间')
    create_time = models.DateTimeField(u'创建时间', default=timezone.now)

    # update_time = models.DateField(u'更新时间', auto_now = True)

    def get_tags(self):
        tags_list = self.tags.split(',')
        while '' in tags_list:
            tags_list.remove('')

        return tags_list

    class Meta:
        verbose_name_plural = verbose_name = u'文章'
        ordering = ['rank', '-is_top', '-create_time']

    def __unicode__(self):
        return self.author.username


class identity(models.Model):
    authc = models.CharField(max_length=100)
    acount = models.CharField(max_length=100)
    ident = models.CharField(max_length=100)

    def __unicode__(self):
        return self.authc


class interface_aotoclient(models.Model):
    platform = models.CharField(max_length=30)
    version = models.CharField(max_length=30)
    result = models.IntegerField()
    result_describe = models.CharField(max_length=60)
    module = models.CharField(max_length=60)
    casename = models.CharField(max_length=80)
    time = models.CharField(max_length=30)
    exception = models.CharField(max_length=80)
    screenshot = models.CharField(max_length=150)
    notice_describe = models.CharField(max_length=20)
    creatdate = models.DateTimeField(default=timezone.now)
    emailtime = models.CharField(max_length=30)

    def _unicode_(self):
        return self.platform

    class Meta:
        ordering = ['-creatdate']


class interface_aotoserver(models.Model):
    host = models.CharField(max_length=60)
    interface = models.CharField(max_length=60)
    result = models.IntegerField()
    result_describe = models.CharField(max_length=90)
    module = models.CharField(max_length=80)
    casename = models.CharField(max_length=180)
    time = models.CharField(max_length=130)
    notice_describe = models.CharField(max_length=120)
    code = models.CharField(max_length=160)
    data = models.CharField(max_length=200, blank=True)
    message = models.CharField(max_length=200, blank=True)
    request_id = models.CharField(max_length=100, blank=True)
    request_time = models.CharField(max_length=40)
    response_time = models.CharField(max_length=40)
    creatdate = models.DateTimeField(default=timezone.now)
    emailtime = models.CharField(max_length=30)

    def _unicode_(self):
        return self.platform

    class Meta:
        ordering = ['-creatdate']


class release_table(models.Model):
    version = models.CharField(max_length=15)
    android = models.CharField(max_length=300)
    ios = models.CharField(max_length=300)
    path_code = models.CharField(max_length=200)
    version_server = models.CharField(max_length=800)
    remarks = models.CharField(max_length=1000)
    creatdate = models.CharField(max_length=80, null=True)

    def _unicode_(self):
        return self.version

    class Meta:
        ordering = ['-id']


class release_itable(models.Model):
    version = models.CharField(max_length=15)
    android = models.CharField(max_length=300)
    ios = models.CharField(max_length=300)
    path_code = models.CharField(max_length=200)
    version_server = models.CharField(max_length=800)
    remarks = models.CharField(max_length=1000)
    creatdate = models.CharField(max_length=80, null=True)

    def _unicode_(self):
        return self.version

    class Meta:
        ordering = ['-id']


class interface_useragent(models.Model):
    result = models.CharField(max_length=300)
    creatdate = models.CharField(max_length=200)

    def _unicode_(self):
        return self.result

    class Meta:
        ordering = ['-creatdate']


class interface_aotoserver_debug(models.Model):
    host = models.CharField(max_length=60)
    interface = models.CharField(max_length=60)
    result = models.IntegerField()
    result_describe = models.CharField(max_length=90)
    module = models.CharField(max_length=80)
    casename = models.CharField(max_length=180)
    time = models.CharField(max_length=130)
    notice_describe = models.CharField(max_length=120)
    code = models.CharField(max_length=900000)
    data = models.CharField(max_length=200, blank=True)
    message = models.CharField(max_length=200, blank=True)
    request_id = models.CharField(max_length=100, blank=True)
    request_time = models.CharField(max_length=40)
    response_time = models.CharField(max_length=40)
    creatdate = models.DateTimeField(default=timezone.now)
    emailtime = models.CharField(max_length=30)

    def _unicode_(self):
        return self.platform

    class Meta:
        ordering = ['-creatdate']


class auto_time_debug(models.Model):
    host = models.CharField(max_length=30)
    is_online = models.IntegerField()
    uid = models.IntegerField()
    usernames = models.CharField(max_length=30)
    passwords = models.CharField(max_length=30)
    nickname = models.CharField(max_length=30)


class load(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=100)
    type = models.IntegerField()
    uid = models.CharField(max_length=20)


class loader_history(models.Model):
    url = models.CharField(max_length=200)
    number = models.IntegerField()
    time = models.CharField(max_length=20)
    is_online = models.IntegerField()
    is_post = models.IntegerField()

    class Meta:
        ordering = ['-id']


class interface_show(models.Model):
    lenth = models.IntegerField()
    version = models.CharField(max_length=10)
    device = models.CharField(max_length=20)
    source = models.CharField(max_length=10)
    creatdate = models.DateTimeField(default=timezone.now)

    class Meta:
        ordering = ['id']


class interface_inf_log(models.Model):
    session_id = models.CharField(max_length=100)
    model = models.CharField(max_length=50)
    case = models.CharField(max_length=100)
    time = models.CharField(max_length=100)
    user = models.CharField(max_length=20)
    uid = models.CharField(max_length=20)
    method = models.CharField(max_length=10)
    url = models.CharField(max_length=200)
    header = models.CharField(max_length=1000)
    body = models.CharField(max_length=300)
    diff = models.CharField(max_length=200)
    message = models.CharField(max_length=200)
    response = models.CharField(max_length=30000)


# class interface_startup(models.Model):
#     device = models.IntegerField(max_length=11)
#     app = models.IntegerField(max_length=11)
#     cold_boot = models.CharField(max_length=255)
#     warn_boot = models.CharField(max_length=255)
#     result = models.CharField(max_length=255)
#     detail = models.CharField(max_length=255)
#     version = models.CharField(max_length=255)
#     timestamp = models.DateTimeField(default=timezone.now)
